package com.heima.admin.controller.v1;

import com.heima.admin.service.AdSensitiveService;
import com.heima.model.admin.dtos.SensitiveDTO;
import com.heima.model.admin.pojos.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/sensitive")
public class AdSensitiveController {

    @Autowired
    AdSensitiveService sensitiveService;

    /**
     * 根据名称查询或查询全部敏感词
     * @param dto
     * @return
     */
    @PostMapping("list")
    public ResponseResult list(@RequestBody SensitiveDTO dto) {
        return sensitiveService.list(dto);
    }

    /**
     * 敏感词修改
     * @param adSensitive
     * @return
     */
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdSensitive adSensitive) {
        return sensitiveService.update(adSensitive);
    }

    /**
     * 添加敏感词
     * @param adSensitive
     * @return
     */
    @PostMapping("save")
    public ResponseResult save(@RequestBody AdSensitive adSensitive) {
        return sensitiveService.insert(adSensitive);
    }


    @DeleteMapping("del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return sensitiveService.delete(id);
    }

    @PostMapping("/sensitives")
    public ResponseResult sensitives() {
        return sensitiveService.selectAllSensitives();
    }

}


